<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>支付完成</title>
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100vh;
      margin: 0;
      padding: 20px;
      box-sizing: border-box;
      text-align: center;
      background-color: #f8f8f8;
      color: #333;
    }
    .container {
      max-width: 500px;
      background-color: #fff;
      border-radius: 12px;
      padding: 30px;
      box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    }
    .title {
      font-size: 22px;
      font-weight: 500;
      margin-bottom: 15px;
    }
    .message {
      font-size: 16px;
      line-height: 1.5;
      color: #666;
      margin-bottom: 25px;
    }
    .loading {
      margin: 15px 0;
    }
    .loading-spinner {
      display: inline-block;
      width: 30px;
      height: 30px;
      border: 3px solid rgba(76, 175, 80, 0.3);
      border-radius: 50%;
      border-top-color: #4CAF50;
      animation: spin 1s ease-in-out infinite;
    }
    @keyframes spin {
      to { transform: rotate(360deg); }
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="title">支付完成</div>
    <div class="message">正在返回小程序，请稍候...</div>
    <div class="loading">
      <div class="loading-spinner"></div>
    </div>
  </div>

  <script>
    // 判断是否在微信小程序web-view环境中
    function isInMiniProgram() {
      return window.__wxjs_environment === 'miniprogram' || /miniprogram/.test(navigator.userAgent.toLowerCase());
    }

    // 延迟一段时间后返回小程序
    setTimeout(function() {
      if (isInMiniProgram()) {
        // 引入微信JS-SDK
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = 'https://res.wx.qq.com/open/js/jweixin-1.3.2.js';
        document.getElementsByTagName('head')[0].appendChild(script);
        
        script.onload = function() {
          // 向小程序发送消息
          wx.miniProgram.postMessage({ 
            data: { action: 'redirect', status: 'success' } 
          });
          
          // 返回小程序
          wx.miniProgram.navigateBack({ delta: 1 });
        };
      } else {
        // 非小程序环境下，直接显示提示
        document.querySelector('.message').innerText = '请关闭当前页面，返回应用继续操作';
      }
    }, 1500);
  </script>
</body>
</html> 